/* Maxim DS3234 public interface */

/* Copyright (C) 2011 David Zanetti
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#define DS3234_H

/* upper byte of the seconds part of the clock is in normal memory */
volatile uint16_t ds3234_msb_s;
volatile uint16_t ds3234_msb_s_pps;
/* era, used to extend range beyond 2037 */
volatile uint8_t ds3234_era; /* only need a few bits */
volatile uint8_t ds3234_era_pps;
/* the last update time */
uint32_t ds3234_reference_s;
uint16_t ds3234_reference_ms;
uint16_t ds3234_reference_rand; /* a random number */

/* FIXME: SPI port where we can find the DS3234 */
/* FIXME: port where DS3234 CS line is */

/* init the chip and set up the timers to generate an rtc */

void ds3234_init(void);

/* we have a valid GPS time presented, align the clock to it */

void ds3234_align(void);

/* print the current time (used by console) */
void ds3234_printtime(void);

/* print the reported temp from the chip (used by console) */
void ds3234_print_temp(void);

/* write the current date/time into the given variables. includes UTC->NTP offset, leap seconds, etc etc */
void ds3234_now_ntp(uint32_t *seconds, uint16_t *fraction);

